<template>
	<view class="uni-navbar">
		<view :class="{ 'uni-navbar--fixed': navFiexd, 'uni-navbar--shadow': shadow, 'uni-navbar--border': border }" :style="{ 'background-color': backgroundColor }"
		 class="uni-navbar__content">
			<uni-status-bar v-if="statusBar" />
			<view :style="{ color: color,backgroundColor: backgroundColor }" class="uni-navbar__header uni-navbar__content_view">
				<view v-if="!leftIconBool" @tap="onClickLeft" class="uni-navbar__header-btns uni-navbar__header-btns-left uni-navbar__content_view">
					<view class="uni-navbar__content_view" v-if="leftIcon.length">
						<uni-icons :color="color" :type="leftIcon" size="48" />
					</view>
					<view :class="{ 'uni-navbar-btn-icon-left': !leftIcon.length }" class="uni-navbar-btn-text uni-navbar__content_view"
					 v-if="leftText.length">
						<text @tap="onClickLeft" :style="{ color: color, fontSize: '34rpx' }">{{ leftText }}</text>
					</view>
					<slot name="left" />
				</view>
				<view v-else class="uni-navbar__header-btns uni-navbar__header-btns-left uni-navbar__content_view">
					<view class="uni-navbar__content_view" v-if="leftIcon.length">
						<uni-icons @tap="onClickLeft" :color="color" :type="leftIcon" size="48" />
					</view>
					<view :class="{ 'uni-navbar-btn-icon-left': !leftIcon.length }" class="uni-navbar-btn-text uni-navbar__content_view"
					 v-if="leftText.length">
						<text @tap="onClickLeft" :style="{ color: color, fontSize: '34rpx' }">{{ leftText }}</text>
					</view>
					<slot name="left" />
				</view>
				<view class="uni-navbar__header-container uni-navbar__content_view">
					<view class="uni-navbar__header-container-inner uni-navbar__content_view" v-if="title.length">
						<!-- #ifdef APP-NVUE -->
						<loading-indicator :animating="true" v-if="loading" style="height: 45rpx; width: 45rpx; color: #888888;margin-right: 10rpx;"></loading-indicator>
						<!-- #endif -->

						<!-- #ifndef APP-NVUE -->
						<view v-if="loading" class="uni-load-more__img uni-load-more__img--ios-H5">
							<image src=""
							 mode="widthFix"></image>
						</view>
						<!-- #endif -->


						<text class="uni-nav-bar-text" :style="titleStyle" v-if="moveRightBtn" @click="onClickRight">{{ title }}</text>
						<text class="uni-nav-bar-text" :style="titleStyle" v-else>{{ title }}</text>


					</view>
					<!-- 标题插槽 -->
					<slot />
				</view>


				<view :style="{'margin-right': moveRightBtn ? '0pt' : ''}" v-if="rightIconBool" :class="title.length ? 'uni-navbar__header-btns-right' : ''"
				 class="uni-navbar__header-btns uni-navbar__content_view">

					<!--  #ifndef  MP-WEIXIN -->
					<view class="uni-navbar__content_view" v-if="rightIcon.length">
						<uni-icons @click="onClickRight" :color="color" :type="rightIcon" size="48" />
					</view>
					<!-- 优先显示图标 -->
					<view class="uni-navbar-btn-text uni-navbar__content_view" v-if="rightText.length && !rightIcon.length">
						<text @click="onClickRight" class="uni-nav-bar-right-text">{{ rightText }}</text>
					</view>
					<slot name="right" />

					<!--  #endif -->
				</view>

				<view v-if="rightButton" class="uni-navbar__header-right-utton" :style="{'margin-right': moveRightBtn ? '80pt' : ''}">
					<view class="rightButton" @click="onClickRight" :style="rightButtonDisable ? 'background-color: #d8d8d8;' : 'background-color: #29c160;'">
						<text class="rightButton-text" :style="rightButtonDisable ? 'color: #b3b2b2;' : 'color: white;'">完成</text>
					</view>
				</view>






			</view>
		</view>
		<view class="uni-navbar__placeholder" v-if="fixed">
			<uni-status-bar v-if="statusBar" />
			<view class="uni-navbar__placeholder-view" />
		</view>
	</view>
</template>

<script>
	import uniStatusBar from "../uni-status-bar/uni-status-bar.vue";
	import uniIcons from "../uni-icons/uni-icons.vue";

	export default {
		name: "UniNavBar",
		components: {
			uniStatusBar,
			uniIcons
		},
		data() {
			return {
				navFiexd: true
			}
		},
		props: {
			title: {
				type: String,
				default: ""
			},
			leftText: {
				type: String,
				default: ""
			},
			rightText: {
				type: String,
				default: ""
			},
			leftIcon: {
				type: String,
				default: ""
			},
			rightIcon: {
				type: String,
				default: ""
			},
			fixed: {
				type: [Boolean, String],
				default: false
			},
			rightButton: {
				type: [Boolean, String],
				default: false
			},
			rightButtonDisable: {
				type: [Boolean, String],
				default: false
			},
			rightIconBool: {
				type: [Boolean, String],
				default: false
			},
			moveRightBtn: {
				type: [Boolean, String],
				default: false
			},
			leftIconBool: {
				type: [Boolean, String],
				default: false
			},
			loading: {
				type: [Boolean, String],
				default: false
			},
			color: {
				type: String,
				default: "#000000"
			},
			backgroundColor: {
				type: String,
				default: "#ebebeb"
			},
			statusBar: {
				type: [Boolean, String],
				default: false
			},
			shadow: {
				type: [String, Boolean],
				default: false
			},
			border: {
				type: [String, Boolean],
				default: true
			},
			titleStyle: {
				type: String,
				default: "font-size: 34rpx; font-weight: 500;"
			}
		},
		watch: {
			fixed: {
				immediate: true,
				handler: function(e) {
					this.navFiexd = e;

				}
			}
		},
		mounted() {
			if (uni.report && this.title !== '') {
				uni.report('title', this.title)
			}
		},
		methods: {
			onClickLeft() {
				this.$emit("clickLeft");
			},
			onClickRight() {
				this.$emit("clickRight");
			},
			onClickIConRight() {
				this.$emit("clickRight");
			},

		}
	};
</script>

<style lang="scss" scoped>
	$nav-height: 88rpx;

	.uni-nav-bar-text {
		/* #ifdef APP-PLUS */
		font-size: 34rpx;
		/* #endif */
		/* #ifndef APP-PLUS */
		font-size: 34rpx;
		/* #endif */

		/* #ifdef MP-WEIXIN */
		width: 200rpx;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		/* #endif */

		/* #ifndef MP-WEIXIN */
		lines: 1;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		/* #endif */


	}

	.uni-nav-bar-right-text {
		font-size: $uni-font-size-base;
	}

	.uni-navbar {
		width: 750rpx;
	}

	.uni-navbar__content {
		position: relative;
		width: 750rpx;
		background-color: $uni-bg-color;
		overflow: hidden;
	}

	.uni-navbar__content_view {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		align-items: center;
		flex-direction: row;
		// background-color: #FFFFFF;
	}

	.uni-navbar__header {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		width: 750rpx;
		height: $nav-height;
		line-height: $nav-height;
		font-size: 32rpx;
		// background-color: #ffffff;
	}

	.uni-navbar__header-btns {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-wrap: nowrap;
		width: 120rpx;
		padding: 0 12rpx;
		justify-content: center;
		align-items: center;
	}

	.uni-navbar__header-btns-left {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		width: 150rpx;
		justify-content: flex-start;
	}

	.uni-navbar__header-btns-right {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		width: 150rpx;
		padding-right: 30rpx;
		justify-content: flex-end;

		/* #ifndef APP-NVUE */
		// margin-right: 65pt;
		/* #endif */
	}

	.uni-navbar__header-container {
		flex: 1;
	}

	.uni-navbar__header-container-inner {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex: 1;
		align-items: center;
		justify-content: center;
		font-size: $uni-font-size-base;
	}


	.uni-navbar__placeholder-view {
		height: $nav-height;
	}

	.uni-navbar--fixed {
		position: fixed;
		z-index: 998;
	}

	.uni-navbar--shadow {
		/* #ifndef APP-NVUE */
		box-shadow: 0 2rpx 12rpx #ccc;
		/* #endif */
	}

	.uni-navbar--border {
		// border-bottom-width: 1rpx;
		// border-bottom-style: solid;
		// border-bottom-color: $uni-border-color;
	}

	.uni-load-more__img {
		width: 45rpx;
		height: 45rpx;
		margin-right: 16rpx;
	}

	.uni-load-more__img--ios-H5 {
		position: relative;
		/* #ifndef APP-NVUE */
		animation: loading-ios-H5 1s 0s step-end infinite;
		/* #endif */

	}

	/* #ifndef APP-NVUE */
	.uni-load-more__img--ios-H5>image {
		position: absolute;
		width: 100%;
		height: 100%;
		left: 0;
		top: 0;
	}

	/* #endif */


	@keyframes loading-ios-H5 {
		0% {
			transform: rotate(0deg);
		}

		8% {
			transform: rotate(30deg);
		}

		16% {
			transform: rotate(60deg);
		}

		24% {
			transform: rotate(90deg);
		}

		32% {
			transform: rotate(120deg);
		}

		40% {
			transform: rotate(150deg);
		}

		48% {
			transform: rotate(180deg);
		}

		56% {
			transform: rotate(210deg);
		}

		64% {
			transform: rotate(240deg);
		}

		73% {
			transform: rotate(270deg);
		}

		82% {
			transform: rotate(300deg);
		}

		91% {
			transform: rotate(330deg);
		}

		100% {
			transform: rotate(360deg);
		}
	}

	.uni-navbar__header-right-utton {
		justify-content: center;
		align-items: center;
		margin-right: 20rpx;
	}

	.rightButton {
		border-radius: 10rpx;
		width: 120rpx;
		background-color: #29c160;
		text-align: center;
		justify-content: center;
		align-items: center;
		/* #ifndef APP-NVUE */
		height: 65rpx;
		/* #endif */


	}

	.rightButton-text {
		/* #ifdef APP-NVUE */
		padding: 16rpx;
		/* #endif */
		font-size: 34rpx;
		font-weight: bold;
		color: white;
	}

	.uni-navbar-btn-icon-left {
		margin-left: 20rpx;
	}
</style>
